 /** 
  * 时间戳格式化函数 
  * @param  {string} format    格式 
  * @param  {int}    timestamp 要格式化的时间 默认为当前时间 
  * @return {string}           格式化的时间字符串 
  */
 module.exports = function (formats, timestamp) {

   formats = formats || 'Y-m-d';

   var zero = function (value) {
     if (value < 10) {
       return '0' + value;

     }
     return value;

   };

   var myDate = timestamp ? new Date(timestamp) : new Date();
   var year = myDate.getFullYear();
   var month = zero(myDate.getMonth() + 1);
   var day = zero(myDate.getDate());
   var hour = zero(myDate.getHours());
   var minite = zero(myDate.getMinutes());
   var second = zero(myDate.getSeconds());

   return formats.replace(/Y|m|d|H|i|s/ig, function (matches) {
     return ({
       Y: year,
       m: month,
       d: day,
       H: hour,
       i: minite,
       s: second
     })[matches];

   })

 };